package com._5704.website.filter;


import com._5704.website.util.JwtUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Component
//废弃
@Deprecated
public class JwtInterceptor implements HandlerInterceptor {
    /**
     * jwt拦截器
     * @param request 请求
     * @param response 响应
     * @param handler handler
     * @return Boolean
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
//        String token = (String) request.getSession().getAttribute("token");
        String token = request.getHeader("token");

        if (JwtUtil.verify(token)){
//            getSubject(request, response).login(token)
            return true;
        }

//        response.sendRedirect("/user/unauthorized");
        return false;

    }
}
